
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>徒手搭建dubbo服务 | Typhoon&#39;s code space</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="typhoon">
    

    
    <meta name="description" content="随着互联网日新月异的发展,传统的软件架构已经满足不了庞大的用户需要和服务可靠性以及稳定性,SOA概念提出后,很多公司都在考虑做服务化, 按照业务模块划分,每一个模块都是一个独立的工程,并且能够提供服务,热点模块也可以部署多个(支付场景)来提高服务可靠性和稳定性,">
<meta name="keywords" content="dubbo">
<meta property="og:type" content="article">
<meta property="og:title" content="徒手搭建dubbo服务">
<meta property="og:url" content="http://scorpioaeolus.oschina.io/2017/12/21/徒手搭建dubbo服务/index.html">
<meta property="og:site_name" content="Typhoon&#39;s code space">
<meta property="og:description" content="随着互联网日新月异的发展,传统的软件架构已经满足不了庞大的用户需要和服务可靠性以及稳定性,SOA概念提出后,很多公司都在考虑做服务化, 按照业务模块划分,每一个模块都是一个独立的工程,并且能够提供服务,热点模块也可以部署多个(支付场景)来提高服务可靠性和稳定性,">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/1.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/2.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/3.jpg">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/4.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/5.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/5.jpg">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/6.jpg">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/gzh.png">
<meta property="og:updated_time" content="2017-12-21T00:53:56.647Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="徒手搭建dubbo服务">
<meta name="twitter:description" content="随着互联网日新月异的发展,传统的软件架构已经满足不了庞大的用户需要和服务可靠性以及稳定性,SOA概念提出后,很多公司都在考虑做服务化, 按照业务模块划分,每一个模块都是一个独立的工程,并且能够提供服务,热点模块也可以部署多个(支付场景)来提高服务可靠性和稳定性,">
<meta name="twitter:image" content="http://scorpioaeolus.oschina.io/typhoon/2017/12/21/徒手搭建dubbo服务/1.png">

    
    <link rel="alternative" href="/atom.xml" title="Typhoon&#39;s code space" type="application/atom+xml">
    
    
    <link rel="icon" href="/typhoon/img/java.png">
    
    
    <link rel="apple-touch-icon" href="/typhoon/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/typhoon/img/jacman.jpg">
    
    <link rel="stylesheet" href="/typhoon/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/typhoon/"><img src="/typhoon/img/java.png" alt="Typhoon&#39;s code space" title="Typhoon&#39;s code space"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/typhoon/" title="Typhoon&#39;s code space">Typhoon&#39;s code space</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/typhoon/">主页</a></li>
					
						<li><a href="/typhoon/archives">归档</a></li>
					
						<li><a href="/typhoon/about">关于</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:scorpioaeolus.oschina.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/typhoon/2017/12/21/徒手搭建dubbo服务/" title="徒手搭建dubbo服务" itemprop="url">徒手搭建dubbo服务</a>
  </h1>
  <p class="article-author">By
       
		<a href="/typhoon/about" title="typhoon" target="_blank" itemprop="author">typhoon</a>
		
  <p class="article-time">
    <time datetime="2017-12-21T00:34:59.000Z" itemprop="datePublished"> Published 2017-12-21</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#一、新建maven工程-amp-添加依赖"><span class="toc-number">1.</span> <span class="toc-text">一、新建maven工程&添加依赖</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#二、添加配置和服务暴露"><span class="toc-number">2.</span> <span class="toc-text">二、添加配置和服务暴露</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#三、编写单元测试-amp-消费服务"><span class="toc-number">3.</span> <span class="toc-text">三、编写单元测试&消费服务</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#附上本人公众号"><span class="toc-number">4.1.</span> <span class="toc-text">附上本人公众号</span></a></li></ol></li></ol>
		
		</div>
		
		<p> 随着互联网日新月异的发展,传统的软件架构已经满足不了庞大的用户需要和服务可靠性以及稳定性,SOA概念提出后,很多公司都在考虑做服务化,<br> 按照业务模块划分,每一个模块都是一个独立的工程,并且能够提供服务,热点模块也可以部署多个(支付场景)来提高服务可靠性和稳定性,</p>
<a id="more"></a>
<p> 目前比较常见的有dubbo(阿里开源),motan(新浪微博开源),gRpc(谷歌)以及国外比较流行的springcloud等。每个框架都有其优势和不足,<br> 对于其他rpc框架暂时不做赘述,今天就国内比较流行的开源rpc框架dubbo,做一下分析和使用.</p>
<h5 id="一、新建maven工程-amp-添加依赖"><a href="#一、新建maven工程-amp-添加依赖" class="headerlink" title="一、新建maven工程&amp;添加依赖"></a>一、新建maven工程&amp;添加依赖</h5><pre><code>1. 新建工程,结构如下图:
</code></pre><img src="/typhoon/2017/12/21/徒手搭建dubbo服务/1.png" alt="dubbo" title="dubbo">
<pre><code>dubbo-server:聚合工程,主要用来管理工程和提供一些通用依赖
dubbo-server-interface:接口工程,定义一些接口和数据传输类;如果其他模块要依赖该模块服务,代码层面要依赖该接口工程
dubbo-server-provider:服务提供工程,提供服务具体实现以及服务暴露

2. 添加基本的依赖
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div></pre></td><td class="code"><pre><div class="line">(I) dubbo-server-interface工程添加dubbo依赖:</div><div class="line">&lt;!-- dubbo依赖 --&gt;    </div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;com.alibaba&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;dubbo&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;2.5.3&lt;/version&gt;</div><div class="line">	&lt;exclusions&gt;</div><div class="line">		&lt;exclusion&gt;</div><div class="line">			&lt;artifactId&gt;netty&lt;/artifactId&gt;</div><div class="line">			&lt;groupId&gt;org.jboss.netty&lt;/groupId&gt;</div><div class="line">		&lt;/exclusion&gt;</div><div class="line">		&lt;exclusion&gt;</div><div class="line">			&lt;artifactId&gt;spring&lt;/artifactId&gt;</div><div class="line">			&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">		&lt;/exclusion&gt;</div><div class="line">	&lt;/exclusions&gt;</div><div class="line">&lt;/dependency&gt;    </div><div class="line">排除dubbo中的netty和spring依赖(dubbo依赖的包版本过低,排除后我们自己引入相关依赖)</div><div class="line"></div><div class="line">(II) dubbo-server-provider添加最简依赖(同时依赖dubbo-server-interface包):</div><div class="line">&lt;!-- netty依赖 --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;io.netty&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;netty&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;3.10.6.Final&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div><div class="line">&lt;!-- mysql connector --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;mysql&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;5.1.41&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div><div class="line">&lt;!-- spring依赖 --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;spring-context&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;	</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;	</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;spring-beans&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;   </div><div class="line">&lt;!-- druid jdbcpool --&gt;	</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;com.alibaba&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;druid&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;1.1.2&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div><div class="line">&lt;!-- fastjson --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;com.alibaba&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;fastjson&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;1.2.28&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;   </div><div class="line">&lt;!-- commons --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">    &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;</div><div class="line">    &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;</div><div class="line">    &lt;version&gt;3.1&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div><div class="line">&lt;!-- 接口依赖 --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;com.typhoon&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;dubbo-server-interface&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div></pre></td></tr></table></figure>
<h5 id="二、添加配置和服务暴露"><a href="#二、添加配置和服务暴露" class="headerlink" title="二、添加配置和服务暴露"></a>二、添加配置和服务暴露</h5><pre><code>1.添加配置文件,如下图:
</code></pre><img src="/typhoon/2017/12/21/徒手搭建dubbo服务/2.png" alt="dubbo" title="dubbo">
<pre><code>jdbc.properties:数据库访问配置文件
server.properties:服务配置文件,目前主要提供服务host和端口配置
dubbo-provider.xml:服务暴露配置文件(dubbo服务暴露可以使用注解,但是有 
些注解名称和spring注解相同,容易混淆,所以dubbo服务暴露和消费都使用配置的方式)
spring-root.xml:项目的主配文件

2.编写服务和服务暴露
 编写一个简单的用户查询接口和实现:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div></pre></td><td class="code"><pre><div class="line">(I)在dubbo-server-interface中定义接口和数据传输类</div><div class="line">    </div><div class="line">UserDto:</div><div class="line">/**</div><div class="line">* 用户信息数据传输类</div><div class="line">* </div><div class="line">* @author Typhoon</div><div class="line">*</div><div class="line">*/</div><div class="line">public class UserDto implements Serializable &#123;</div><div class="line"></div><div class="line">/**</div><div class="line"> * </div><div class="line"> */</div><div class="line">private static final long serialVersionUID = 3059861301424720410L;</div><div class="line"></div><div class="line">/**</div><div class="line"> * id</div><div class="line"> */</div><div class="line">private Long id;</div><div class="line"></div><div class="line">/**</div><div class="line"> * 姓名</div><div class="line"> */</div><div class="line">private String name;</div><div class="line"></div><div class="line">/**</div><div class="line"> * 创建时间</div><div class="line"> */</div><div class="line">private Date createTime;</div><div class="line"></div><div class="line">//省略get和set方法</div><div class="line">&#125;</div><div class="line"></div><div class="line">UserService:</div><div class="line">public interface UserService &#123;</div><div class="line"></div><div class="line">UserDto queryByPK(Long id);</div><div class="line"></div><div class="line">&#125;</div><div class="line"></div><div class="line">(II)编写服务实现</div><div class="line"></div><div class="line">User:</div><div class="line">/**</div><div class="line">* 用户信息实体类</div><div class="line">* </div><div class="line">* @author Typhoon</div><div class="line">*</div><div class="line">*/</div><div class="line">public class User implements Serializable &#123;</div><div class="line">/**</div><div class="line"> * </div><div class="line"> */</div><div class="line">private static final long serialVersionUID = 3059861301424720410L;</div><div class="line"></div><div class="line">/**</div><div class="line"> * id</div><div class="line"> */</div><div class="line">private Long id;</div><div class="line"></div><div class="line">/**</div><div class="line"> * 姓名</div><div class="line"> */</div><div class="line">private String name;</div><div class="line"></div><div class="line">/**</div><div class="line"> * 创建时间</div><div class="line"> */</div><div class="line">private Date createTime;</div><div class="line">//省略set和get方法</div><div class="line">&#125;</div><div class="line"></div><div class="line">UserServiceImpl:</div><div class="line">@Service(&quot;userService&quot;)</div><div class="line">public class UserServiceImpl implements UserService &#123;</div><div class="line"></div><div class="line">@Resource</div><div class="line">UserDao userDao;</div><div class="line"></div><div class="line">@Override</div><div class="line">public UserDto queryByPK(Long id) &#123;</div><div class="line">	User user = this.userDao.queryByPK(id);</div><div class="line">	if(null == user) &#123;</div><div class="line">		return null;</div><div class="line">	&#125;</div><div class="line">	UserDto dto = new UserDto();</div><div class="line">	dto.setId(user.getId());</div><div class="line">	dto.setName(user.getName());</div><div class="line">	dto.setCreateTime(user.getCreateTime());</div><div class="line">	return dto;</div><div class="line">&#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line">UserDao:</div><div class="line">@Repository(&quot;userDao&quot;)</div><div class="line">public class UserDao &#123;</div><div class="line"></div><div class="line">JdbcTemplate jdbcTemplate = DataSourceUtils.getJdbcTemplate();</div><div class="line"></div><div class="line">public User queryByPK(Long id) &#123;</div><div class="line">	String sql = &quot;		select * from user where id = ? limit 1 	&quot;;</div><div class="line">	List&lt;User&gt; list = this.jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(User.class), id);</div><div class="line">	if(null == list || list.isEmpty()) &#123;</div><div class="line">		return null;</div><div class="line">	&#125;</div><div class="line">	return list.get(0);</div><div class="line">&#125;</div><div class="line"></div><div class="line">&#125;</div><div class="line"></div><div class="line">(III)配置服务暴露</div><div class="line"></div><div class="line">在dubbo-provider.xml中添加一下配置:</div><div class="line">&lt;dubbo:application name=&quot;dubbo-provider&quot;/&gt;</div><div class="line">&lt;dubbo:registry register=&quot;false&quot; /&gt;</div><div class="line">&lt;!--     &lt;dubbo:registry protocol=&quot;zookeeper&quot; address=&quot;$&#123;dubbo.zookeeper.url&#125;&quot; register=&quot;$&#123;dubbo.register&#125;&quot;/&gt; --&gt;</div><div class="line">&lt;!--  &lt;dubbo:provider timeout=&quot;$&#123;dubbo.timeout&#125;&quot; retries=&quot;0&quot;&gt;&lt;/dubbo:provider&gt; --&gt;</div><div class="line"></div><div class="line">&lt;dubbo:protocol name=&quot;dubbo&quot; port=&quot;$&#123;dubbo.protocol.dubbo.port&#125;&quot; host=&quot;$&#123;dubbo.protocol.dubbo.host&#125;&quot; accesslog=&quot;$&#123;dubbo.protocol.dubbo.accessLog&#125;&quot;/&gt;</div><div class="line"></div><div class="line">&lt;dubbo:service interface=&quot;org.dubbo.server.service.UserService&quot; ref=&quot;userService&quot; protocol=&quot;dubbo&quot;   /&gt;</div><div class="line">&lt;dubbo:application /&gt;用来配置当前模块的名称,主要用来做调用分析</div><div class="line">&lt;dubbo:registry /&gt;用来做配置中心(比如zookeeper),该实例中我们暂不是用注册中心,所以配置register=false(如果没有&lt;dubbo:registry /&gt;节点,服务无法启动)</div><div class="line">&lt;dubbo:protocol /&gt;用来配置服务协议,常用的有dubbo协议,hessian协议,此处我们使用dubbo协议,协议中需要配置服务暴露主机和端口</div><div class="line">&lt;dubbo:service /&gt;改节点才是我们具体服务的暴露,interface需要配置接口,ref配置spring容器注入的bean引用,protocol就是我们上述的协议配置.</div><div class="line"></div><div class="line"></div><div class="line">然后把dubbo-provider.xml导入到项目主配文件spring-root.xml中,这样工程启动的时候会加载dubbo-provider.xml中配置</div><div class="line"></div><div class="line"></div><div class="line">(IV)编写服务启动门面类&amp;启动服务</div><div class="line"></div><div class="line">经过上述步骤,我们的dubbo服务已经编写和配置完成,为了能够独立启动服务,还需要一个门面类用来启动dubbo服务(部署到linux环境的时候使用shell脚本运行该类来启动服务),代码如下:</div><div class="line">public class ProviderServer &#123;</div><div class="line">public static void main(String[] args) throws Exception &#123;</div><div class="line">	AbstractApplicationContext context = new ClassPathXmlApplicationContext(&quot;spring-root.xml&quot;);</div><div class="line">	context.start();</div><div class="line">	</div><div class="line">	CountDownLatch count = new CountDownLatch(1);</div><div class="line">	count.await();</div><div class="line">	context.close();</div><div class="line">&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>然后运行该门面类,看到如下结果:
</code></pre><img src="/typhoon/2017/12/21/徒手搭建dubbo服务/3.jpg" alt="dubbo" title="dubbo">
<p>没有看到异常,我们暂且认为服务启动成功了(其实了解过netty的朋友,可以从最后一行看出来,nettserver绑定成功,服务暴露在本机20289端口)</p>
<h5 id="三、编写单元测试-amp-消费服务"><a href="#三、编写单元测试-amp-消费服务" class="headerlink" title="三、编写单元测试&amp;消费服务"></a>三、编写单元测试&amp;消费服务</h5><pre><code>经过上述步骤,dubbo服务已经启动了,接下来我们就需要模拟消费者去消费服务.

1. 编写单元测试消费服务
编写dubbo单元测试基类,代码如下:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line">* 免配置dubbo服务单元测试</div><div class="line">* </div><div class="line">* @author Typhoon</div><div class="line">* @date 2017-08-03 17:35 Thursday</div><div class="line">* @since V1.3.1</div><div class="line">* @param &lt;T&gt;</div><div class="line">*/</div><div class="line">@SuppressWarnings(&quot;unchecked&quot;)</div><div class="line">public abstract class AbstractBaseTest&lt;T&gt; &#123;</div><div class="line">private ApplicationConfig application = null;</div><div class="line">private Class &lt;T&gt; clazz = (Class &lt;T&gt;) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];   </div><div class="line">private static final String appName = &quot;dubbo-consumer&quot;;</div><div class="line">public AbstractBaseTest() &#123;</div><div class="line">	application = new ApplicationConfig();</div><div class="line">	application.setName(appName);</div><div class="line">	//registry.setAddress(zkUrl);</div><div class="line">	// 注意：ReferenceConfig为重对象，内部封装了与注册中心的连接，以及与服务提供方的连接</div><div class="line">&#125;</div><div class="line"> T getService() &#123;</div><div class="line">		// 引用远程服务</div><div class="line">		ReferenceConfig&lt;T&gt; reference = new ReferenceConfig&lt;T&gt;(); // 此实例很重，封装了与注册中心的连接以及与提供者的连接，请自行缓存，否则可能造成内存和连接泄漏</div><div class="line">		reference.setApplication(application);</div><div class="line">		reference.setUrl(getDubboUrl());</div><div class="line">		//reference.setFilter(&quot;consumerFilter&quot;);</div><div class="line">		reference.setInterface(clazz);</div><div class="line">		reference.setTimeout(getTimeout());</div><div class="line">		// 和本地bean一样使用xxxService</div><div class="line">		return reference.get(); // 注意：此代理对象内部封装了所有通讯细节，对象较重，请缓存复用</div><div class="line"> &#125;;</div><div class="line"> </div><div class="line"> abstract String getDubboUrl();</div><div class="line"> </div><div class="line"> /**</div><div class="line">  * 默认超时时间30秒</div><div class="line">  * </div><div class="line"> * @return</div><div class="line"> */</div><div class="line">int  getTimeout() &#123;</div><div class="line">	 return 30000;</div><div class="line"> &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>编写单元测试类,代码如下:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">public class UserServiceTest extends AbstractBaseTest&lt;UserService&gt; &#123;</div><div class="line"></div><div class="line">UserService userService = this.getService();</div><div class="line"></div><div class="line">@Override</div><div class="line">String getDubboUrl() &#123;</div><div class="line">	return &quot;dubbo://localhost:20289&quot;;</div><div class="line">&#125;</div><div class="line"></div><div class="line">@Test</div><div class="line">public void testQueryByPK() &#123;</div><div class="line">	UserDto userDto = this.userService.queryByPK(1L);</div><div class="line">	System.out.println(&quot;响应:&quot; + userDto);</div><div class="line">&#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>运行单元测试,可以看到如下结果:
</code></pre><img src="/typhoon/2017/12/21/徒手搭建dubbo服务/4.png" alt="dubbo" title="dubbo">
<p>可以看出,使用单元测试模拟消费者已经成功消费了dubbo服务,可能会有人觉得这是不是本地调用而不是dubbo服务调用,<br>为了验证我们的结论,我们下一步将使用真实的项目去依赖和消费服务</p>
<pre><code>2. 编写单元测试消费服务  
 (I)新建消费者工程
</code></pre><img src="/typhoon/2017/12/21/徒手搭建dubbo服务/5.png" alt="dubbo" title="dubbo">
<pre><code>在dubbo-consumer-provider中添加dubbo-consumer-interface、dubbo-server-interface以及其他dubbo和spring相关依赖:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div></pre></td><td class="code"><pre><div class="line">&lt;!-- netty依赖 --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">    &lt;groupId&gt;io.netty&lt;/groupId&gt;</div><div class="line">    &lt;artifactId&gt;netty&lt;/artifactId&gt;</div><div class="line">    &lt;version&gt;3.10.6.Final&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div><div class="line"></div><div class="line">&lt;!--  spring依赖  --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;spring-context&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;	</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;	</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;spring-beans&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">&lt;/dependency&gt; </div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;org.springframework&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;spring-test&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;4.3.7.RELEASE&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;        </div><div class="line">&lt;!-- fastjson --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">	&lt;groupId&gt;com.alibaba&lt;/groupId&gt;</div><div class="line">	&lt;artifactId&gt;fastjson&lt;/artifactId&gt;</div><div class="line">	&lt;version&gt;1.2.28&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;   </div><div class="line">&lt;!-- commons --&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">    &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;</div><div class="line">    &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;</div><div class="line">    &lt;version&gt;3.1&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">    &lt;groupId&gt;com.typhoon&lt;/groupId&gt;</div><div class="line">    &lt;artifactId&gt;dubbo-consumer-interface&lt;/artifactId&gt;</div><div class="line">    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div><div class="line">&lt;dependency&gt;</div><div class="line">    &lt;groupId&gt;com.typhoon&lt;/groupId&gt;</div><div class="line">    &lt;artifactId&gt;dubbo-server-interface&lt;/artifactId&gt;</div><div class="line">    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;</div><div class="line">&lt;/dependency&gt;</div></pre></td></tr></table></figure>
<pre><code>(II)在dubbo-consumer-interface和dubbo-consumer-provider中服务消费接口和实现.
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">ImitateService:</div><div class="line">public interface ImitateService &#123;</div><div class="line">	</div><div class="line">	void imitateQueryUserById(Long id);</div><div class="line">	</div><div class="line">&#125;</div><div class="line"></div><div class="line">ImitateServiceImpl:</div><div class="line">@Service(&quot;imitateService&quot;)</div><div class="line">public class ImitateServiceImpl implements ImitateService &#123;</div><div class="line">	</div><div class="line">	@Resource</div><div class="line">	UserService userService;</div><div class="line"></div><div class="line">	@Override</div><div class="line">	public void imitateQueryUserById(Long id) &#123;</div><div class="line">		UserDto dto =	 this.userService.queryByPK(id);</div><div class="line">		System.out.println(&quot;远程调用userService查询结果:&quot; + dto);</div><div class="line">	&#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code> 注意:使用@Resource标注UserService后,我们可以像调用本地服务一样调用rpc服务

(III) 添加服务依赖配置
</code></pre><p> src/main/resources目录下添加dubbo-consumer.xml配置,内容如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">&lt;dubbo:application name=&quot;dubbo-consumer&quot;/&gt;</div><div class="line"> &lt;!-- 用户信息服务依赖 --&gt;</div><div class="line">&lt;dubbo:reference interface=&quot;org.dubbo.server.service.UserService&quot;  url=&quot;dubbo://localhost:20289&quot; id=&quot;userService&quot; protocol=&quot;dubbo&quot; timeout=&quot;30000&quot; /&gt;</div></pre></td></tr></table></figure></p>
<p><dubbo:application>和上述服务提供者一样.</dubbo:application></p>
<p><dubbo:reference>定义dubbo服务依赖,本质上是将dubbo服务本地化</dubbo:reference></p>
<p>然后将dubbo-consumer.xml导入到spring-root.xml中</p>
<pre><code>(IV)编写测试验证
 在dubbo-consumer-provider中新建RpcConsumer:
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">public class RpcConsumer &#123;</div><div class="line"></div><div class="line">@SuppressWarnings(&quot;resource&quot;)</div><div class="line">public static void main(String[] args) &#123;</div><div class="line">	AbstractApplicationContext context = new ClassPathXmlApplicationContext(&quot;spring-root.xml&quot;);</div><div class="line">	context.start();</div><div class="line">	ImitateService imitateService = SpringContextUtil.getBean(&quot;imitateService&quot;, ImitateService.class);</div><div class="line">	imitateService.imitateQueryUserById(1L);</div><div class="line">&#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>然后以debug方式运行RpcConsumer：
</code></pre><img src="/typhoon/2017/12/21/徒手搭建dubbo服务/5.jpg" alt="dubbo" title="dubbo">
<pre><code>跟进去具体服务,逐步运行看到如下结果:
</code></pre><img src="/typhoon/2017/12/21/徒手搭建dubbo服务/6.jpg" alt="dubbo" title="dubbo">
<p>终于大功告成,得到了我们想要的结果!</p>
<h5 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h5><p>经过一番波折,我们实现了dubbo服务的搭建、启动和消费,但是可以发现上述的服务是点到点直连,如果server挂掉,<br>consumer就无法调用了,如果我们使用了zk注册中心,server启动成功后注册到zk,consumer消费的时候先去zk订阅,<br>如果有可用节点,zk会根据配置的调用策略(轮训、最少访问等)提供一个节点给consumer,然后consumer使用拿到的节点url去连接对应的服务提供者节点.</p>
<p><strong><em>PS:原创不易,多多支持!</em></strong></p>
<h6 id="附上本人公众号"><a href="#附上本人公众号" class="headerlink" title="附上本人公众号"></a>附上本人公众号</h6><img src="/typhoon/2017/12/21/徒手搭建dubbo服务/gzh.png" alt="dubbo" title="dubbo">  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/typhoon/categories/dubbo/">dubbo</a>
</div>


  <div class="article-tags">
  
  <span></span> <a href="/typhoon/tags/dubbo/">dubbo</a>
  </div>

</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://scorpioaeolus.oschina.io/2017/12/21/徒手搭建dubbo服务/" data-title="徒手搭建dubbo服务 | Typhoon&#39;s code space" data-tsina="null" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/typhoon/2018/04/20/阿里面试题/" title="阿里面试题">
  <strong>上一篇：</strong><br/>
  <span>
  阿里面试题</span>
</a>
</div>


<div class="next">
<a href="/typhoon/2017/09/17/jdbcTemplate实现HA/"  title="jdbcTemplate实现HA">
 <strong>下一篇：</strong><br/> 
 <span>jdbcTemplate实现HA
</span>
</a>
</div>

</nav>

	


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#一、新建maven工程-amp-添加依赖"><span class="toc-number">1.</span> <span class="toc-text">一、新建maven工程&添加依赖</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#二、添加配置和服务暴露"><span class="toc-number">2.</span> <span class="toc-text">二、添加配置和服务暴露</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#三、编写单元测试-amp-消费服务"><span class="toc-number">3.</span> <span class="toc-text">三、编写单元测试&消费服务</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#附上本人公众号"><span class="toc-number">4.1.</span> <span class="toc-text">附上本人公众号</span></a></li></ol></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/typhoon/categories/dubbo/" title="dubbo">dubbo<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java性能优化/" title="java性能优化">java性能优化<sup>17</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java源码分析/" title="java源码分析">java源码分析<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/motan/" title="motan">motan<sup>2</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/spring/" title="spring">spring<sup>11</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springboot/" title="springboot">springboot<sup>28</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springmvc/" title="springmvc">springmvc<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/容器/" title="容器">容器<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/工具/" title="工具">工具<sup>7</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/性能优化/" title="性能优化">性能优化<sup>5</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/架构/" title="架构">架构<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/案例分析/" title="案例分析">案例分析<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/缓存/" title="缓存">缓存<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/面试题/" title="面试题">面试题<sup>1</sup></a></li>
		  
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/typhoon/tags/springboot/" title="springboot">springboot<sup>28</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/java性能优化/" title="java性能优化">java性能优化<sup>9</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/限流/" title="限流">限流<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring5/" title="Spring5">Spring5<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/案例分析/" title="案例分析">案例分析<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/性能优化/" title="性能优化">性能优化<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring/" title="Spring">Spring<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo/" title="dubbo">dubbo<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/分页/" title="分页">分页<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/并发/" title="并发">并发<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/异常拦截/" title="异常拦截">异常拦截<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo分布式事务/" title="dubbo分布式事务">dubbo分布式事务<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/自带图片/" title="自带图片">自带图片<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/svn导出mvn项目/" title="svn导出mvn项目">svn导出mvn项目<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo过滤器/" title="dubbo过滤器">dubbo过滤器<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/排序性能对比/" title="排序性能对比">排序性能对比<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/ListenableFuture/" title="ListenableFuture">ListenableFuture<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/PropertyChangeListener/" title="PropertyChangeListener">PropertyChangeListener<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/jdbcTemplate高可用/" title="jdbcTemplate高可用">jdbcTemplate高可用<sup>1</sup></a></li>
			
		
		</ul>
</div>


  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=null&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m a java coder. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
		<a href="mailto:ScorpioAeolus@163.com" target="_blank" class="icon-email" title="Email Me"></a>
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2019 
		
		<a href="/typhoon/about" target="_blank" title="typhoon">typhoon</a>
		
		
		</p>
</div>
</footer>
    <script src="/typhoon/js/jquery-2.0.3.min.js"></script>
<script src="/typhoon/js/jquery.imagesloaded.min.js"></script>
<script src="/typhoon/js/gallery.js"></script>
<script src="/typhoon/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>









<link rel="stylesheet" href="/typhoon/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/typhoon/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/typhoon/img/scrollup.png"/></a>
	</div>
	<script src="/typhoon/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
